package breeze.pixel.weather.search_city.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.qweather.sdk.bean.geo.GeoBean;

import java.util.List;

import breeze.pixel.weather.R;
import breeze.pixel.weather.adapter.weather.CityAdapter;
import breeze.pixel.weather.apps_util.views.mtextview.MTextView;

public class SearchCityAdapter extends BaseAdapter {

    private final Context context;
    private final List<CityAdapter.LocationBean> datas;
    public SearchCityAdapter(Context context, List<CityAdapter.LocationBean> list){
        this.context = context;
        this.datas = list;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MViewHolder holder;
        CityAdapter.LocationBean bean = datas.get(position);
        if(convertView == null){
            holder = new MViewHolder();
            convertView = LayoutInflater.from(this.context).inflate(R.layout.city_select_item_view,null);
            holder.textView = convertView.findViewById(R.id.city_select_view_name);
            convertView.setTag(holder);
        }else{
            holder = (MViewHolder) convertView.getTag();
        }
        holder.textView.setText(String.format("%s-%s-%s", bean.getName(), bean.getAdm2(), bean.getAdm1()));
        return convertView;
    }

    static class MViewHolder{
        MTextView textView;
    }
}
